package br.com.felix.fwt.svg.shapes;

import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

import br.com.felix.fwt.svg.SVG;
import br.com.felix.fwt.svg.SVGBuilder;
import br.com.felix.fwt.svg.SVGColor;

public class SVGPolyline implements SVG {

	private List<Point> points;
	
	private SVGColor stroke;
	
	private int strokeWidth;
	

	private SVGColor fill;
	
	public SVGPolyline(){
		points = new ArrayList<Point>();
	}
	
	public void addPoint(Point p){
		points.add(p);
	}
	
	public void addPoint(int x, int y){
		points.add(new Point(x,y));
	}
	
	@Override
	public void toSVG(SVGBuilder svgBuilder) {
		svgBuilder.createElement(getElementName())
				.attribute("points", getPoints())
				.attribute("stroke", stroke)
				.attribute("stroke-width", strokeWidth)
				.attribute("fill", fill)
				.endElementNoBody();
	}

	protected String getElementName() {
		return "polyline";
	}
	
	
	private String getPoints() {
		StringBuilder strb = new StringBuilder();
		for(Point p: points){
			strb.append(p.x).append(",").append(p.y).append(" ");
		}
		return strb.toString();
	}

	
	public SVGPolyline stroke(SVGColor stroke){
		this.stroke = stroke;
		return this;
	}
	
	public SVGPolyline strokeWidth(int strokeWidth){
		this.strokeWidth = strokeWidth;
		return this;
	}
	
	
	public SVGPolyline fill(SVGColor fill){
		this.fill = fill;
		return this;
	}

}
